package com.zy.resp;

import com.zy.util.JsonUtil;

import java.io.Serializable;

public class ZyResult  implements Serializable {

    private static final long serialVersionUID = -999362211833007653L;


    /**
     * 返回结果编码，成功0
     *
     */
    protected final int code;

    /**
     * 返回消息，一般放置可追溯的错误消息
     */
    protected final String msg;

    /**
     * 返回数据
     */
    protected final Object data;




    private ZyResult( int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data=data;
    }

    public static String  fail(int code, String msg){
        return  JsonUtil.toJSONString(new ZyResult(code,msg,null));
    }

    public static String success(Object data){
        return JsonUtil.toJSONString(new ZyResult(0,"操作成功",data));
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }
}
